#include <QtCore/QCoreApplication>
#include "myhelper.h"
#include  "systemfile.h"
#include "frmmain.h"
systemFile *sysInfo;
void customMessageHandler(QtMsgType type, const char *msg)
{
        QString txt;
        QString cuurentT=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
        switch (type) {
        //调试信息提示
        case QtDebugMsg:
                txt = QString("%1=Debug: %2").arg(cuurentT).arg(msg);
                break;
        //一般的warning提示
        case QtWarningMsg:
                txt = QString("%1=Warning: %2").arg(cuurentT).arg(msg);
        break;
        //严重错误提示
        case QtCriticalMsg:
                txt = QString("%1=Critical: %2").arg(cuurentT).arg(msg);
        break;
        //致命错误提示
        case QtFatalMsg:
                txt = QString("%1=Fatal: %2").arg(cuurentT).arg(msg);
                abort();
        }
        QString logname=QDate::currentDate().toString("yyyyMMdd").append(".txt");
        QString delename=QDate::currentDate().addDays(-7).toString("yyyyMMdd").append(".txt");
        QFile outFile(logname);
        outFile.open(QIODevice::WriteOnly | QIODevice::Append);
        QTextStream ts(&outFile);
        ts << txt << endl;
        QFile defile(delename);
        if(defile.exists())
        {
        defile.remove();
        }
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QCoreApplication::addLibraryPath("./plugins");
    qInstallMsgHandler(customMessageHandler);
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    sysInfo =new systemFile();
    frmMain w;
    return a.exec();
}
